var express = require('express');
var router = express.Router();
const mongoose = require('mongoose');

/* GET home page. */

// router.get('/', function(req, res, next) {
//   mongoose.connect('mongodb://localhost/test');
//   console.log(req.query.name)

//   var Cat = mongoose.models.Cat||mongoose.model('Cat', { name: String });
//   var kitty = new Cat({ name: req.query.name });

//     kitty.save().then(function(data){
//        res.json(data)
//     } );
// });


// router.post('/', function(req, res, next) {
//   mongoose.connect('mongodb://localhost/test');
//   var Cat = mongoose.models.Cat||mongoose.model('Cat', { name: String });
//   var kitty = new Cat({ name: req.body.name });

//     kitty.save().then(function(data){
//        res.json(data)
//     } );
// });

router.post('/', function(req, res, next) {
  mongoose.connect('mongodb://localhost/test');
  const Cat = mongoose.models.Cat||mongoose.model('Cat', { name: String,password: Number });
  //console.log(Cat)
  const kitty = new Cat({ name:req.body.name,password:req.body.password });
  kitty.save().then((data) => {
    res.json(data);
  });
});


router.get('/', function(req, res, next) {
  mongoose.connect('mongodb://localhost/test');
  const Cat = mongoose.models.Cat||mongoose.model('Cat', { name: String,password: Number });
  //console.log(Cat)
  const kitty = new Cat({ name:req.query.name,password:req.query.password });
  kitty.save().then((data) => {
    res.json(data);
  });
});

module.exports = router;
